package com.xhui.vimarket.zkplus.zul.attr.ada.impl;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Checkbox;
com.xhui.vimarket.zkplusui.vimarket.zkplus.util.Compcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zulcom.xhui.vimarket.zkplusda;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrTmpl;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.impl.AttrTmplImpl;
import com.xhui.vicom.xhui.vimarket.zkplusul.attr.mod.impl.AttrBaseComp;
import com.xhui.vimarket.zkplus.zul.panel.GroupPanel;

/**
 * 可选包属性适配器.
 * 取空属性实例方案：全部不生成
 * 按钮文本，composer方案：采用默认的值显示和设置composer,或根据传入的值设置
 * checkbox，composer方案：采用无composer
 * 
 * @author wuyx
 * @version Revision 1.0.0
 * 
 */
public class OptionalOfferAda extends DefaultAttrAda {
    
    /**
     * ins.
     */
    private static AttrAda ins = new OptionalOfferAda();
    
    /**
     * instance.
     * @return AttrAda
     */
    public static AttrAda instance() {
        return OptionalOfferAda.ins;
    }
    
    /**
     * 构造函数.
     */
    protected OptionalOfferAda() {
    }
    
    @Override
    public Component getAttrTmplCompStr(final String displayMode, final AttrTmpl attrTmpl,
        final String sComposer, final String param1, final String param2, Component parentComp) {
        if (displayMode == null) {
            return null;
        } else if (AttrTmplImpl.MODE_CHECKBOX.equals(displayMode) || AttrTmplImpl.MODE_CHECKBOX_BYINST.equals(displayMode)) {
            Checkbox checkbox = new Checkbox();
            checkbox.setLabel("");
            ComposerUtil.bindComposer(checkbox,
                "com.xhui.crm2.order.ui.sale.optionoffer.attrcomp.OptionOfferAttrCheckboxComposer",
                parentComp);
            return checkbox;
            
            // return "<checkbox apply=\"com.xhui.crm2.order.ui.sale.optionoffer.attrcomp.OptionOfferAttrCheckboxComposer\" label=\"\" />";
        } else if (AttrTmplImpl.MODE_GROUPBOX.equals(displcom.xhui.vimarket.zkplus         //            String str = "<div use=\"com.xhui.vimarket.zkplus.zul.panel.GroupPanel\" "
            //                + "apply=\"com.xhui.crm2.order.ui.sale.attrcomp.OptionalGboxComposer\">"
            //                + "<div><span><label /></span><span></span></div></div>";
            //            Component comp = Executions.createComponentsDirectly(str, null, parentComp, null);
            GroupPanel comp = new GroupPanel();
            comp.onCreate();
            ComposerUtil.bindComposer(comp,
                "com.xhui.crm2.order.ui.sale.attrcomp.OptionalGboxComposer", parentComp);
            return comp;
        }
        return super.getAttrTmplCompStr(displayMode, attrTmpl, sComposer, param1, param2,
            parentComp);
    }
    
    @Override
    public boolean isCreateNullAttrInst(final String displayMode, final AttrTmpl attrTmpl) {
        return super.isCreateNullAttrInst(displayMode, attrTmpl);
    }
    
    @Override
    public int getSortType() {
        return AttrBaseComp.SORT_BY_ORDER;
    }
    
}
